package com.example.common.config;

import com.example.bean.MsgHandlerMapping;
import com.example.common.converter.BuiltinMsgTypeParser;
import com.example.common.converter.MsgTypeParser;
import com.example.common.netty.HandlerNetty;
import com.example.common.scan.HandlerScanner;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public  class ConfigurationSupport {

    @Bean
    public HandlerScanner handlerScanner(MsgTypeParser msgTypeParser) {
        return new HandlerScanner("com.example.handler",new MsgHandlerMapping(),msgTypeParser);
    }

    @Bean
    public MsgHandlerMapping mapping(){
        return new MsgHandlerMapping();
    }

    @Bean
    public  MsgTypeParser msgTypeParser(){
        //默认
        return new BuiltinMsgTypeParser();
    };

    @Bean
    @ConditionalOnMissingBean
    public HandlerNetty handlerNetty(){
        return new HandlerNetty();
    }
}